import java.util.random.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
class MyThread extends Thread{
    private String name;
    public MyThread(String name){
        this.name = name;
    }
    @Override
    public void run(){
        while(true)
            System.out.println(name+":"+"正在运行！");
    }
}

class MyRunnable implements Runnable{
    private String name;
    public MyRunnable(String name){
        this.name = name;
    }
    @Override
    public void run(){
        int cnt = 100;
        while(cnt!=0){
            cnt--;
            System.out.println(name+"正在运行");
        }
    }
}

class MyRunnable2 implements Runnable{
    private String name;
    Integer count;
    private Lock lock = new ReentrantLock();
    public MyRunnable2(String name,Integer count){
        this.name = name;
        this.count = count;
    }
    @Override
    public void run(){
        while(true){
            lock.lock();
            try{
                System.out.println(name+":count为"+count);
                count--;
            }finally {
                lock.unlock();
            }

        }
    }
}

class MyRunnable3 implements Runnable{
    private String name;
    Integer count;
    private Lock lock = new ReentrantLock();
    public MyRunnable3(String name,Integer count){
        this.name = name;
        this.count = count;
    }
    @Override
    public void run(){
        while(true){
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"asdasdsa");
            lock.lock();
            try{
                System.out.println(name+":count为"+count);
                count = 1000000000;
            }finally {
                lock.unlock();
            }

        }
    }
}


public class Main {
    public static void main(String[] args) {
//        MyThread a1 = new MyThread("A");
//        MyThread a2 = new MyThread("B");
//        a1.start();
//        a2.start();
        Integer count = 1;
//        new Thread(new MyRunnable("A")).start();
//        new Thread(new MyRunnable("B")).start();
        new  Thread(new MyRunnable2("A",count)).start();
        new  Thread(new MyRunnable3("B",count)).start();
    }
}